package cn.springcloud.fix.gateway.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.cloud.gateway.route.RouteDefinitionLocator;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import reactor.core.publisher.Flux;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/route")
public class TestController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private RouteDefinitionLocator routeDefinitionLocator;

    @GetMapping("/sayHello")
    public String sayHello(String name) {
        String url = "http://provider-service/hello?name=" + name;
        return restTemplate.getForObject(url, String.class);
    }

    @RequestMapping("/routes")
    public Flux<RouteDefinition> getRouteDefinitions() {
        return routeDefinitionLocator.getRouteDefinitions();
    }
}
